// JavaScript Document
var SiteMain = (function() {
	function init(){
		setBG();
		slider.init();
		//continue_step2();
		home.init();
		slider_bottom.init();
		hoverMenu();
		hoverMenu2();
		createRating();
		createSlide();

		activeCurrentMenu();
		//initBG();
	}
	function initBG(){
		var arrow = webroot + 'images/arrow.png';
		$('.commonPage .box-left ul.main-menu li, .commonPage .box-left ul.main-menu-2 li').each(function(){
			var color = $(this).attr('color');
			var textcolor = $(this).attr('textcolor');
			if($(this).hasClass('has-sub')){
				$(this).find('a').css({'color':'#' + textcolor});
				$(this).find('ul.sub').css({'background':'#' + color});
				$(this).css({'background':'url('+arrow+') no-repeat scroll 145px center #' + color});
			}else{
				$(this).css({'background':'#' + color});
				$(this).find('ul.sub').css({'background':'#' + color});
				$(this).find('a').css({'color':'#' + textcolor});
			}
			
		});
		
	}
	function hoverMenu2(){
		$('.commonPage .navigation-container-2 ul.main-menu-2 li').hover(function(){
			var color = $(this).attr('color');
			$(this).css({'background':'#' + color});
		},function(){
			$(this).removeAttr('style');
		});
		
		$('.commonPage .navigation-container-2 ul.main-menu-2 li ul.sub li').hover(function(){
			var color = $(this).parent().parent().attr('color');
			$(this).css({'background':'#' + color});
		},function(){
			$(this).removeAttr('style');
		});
		
		$('.commonPage .navigation-container-2 ul.main-menu-2 li ul.sub li ul.sub li').hover(function(){
			var color = $(this).parent().parent().parent().parent().attr('color');
			$(this).css({'background':'#' + color});
		},function(){
			
		});
	}
	function activeCurrentMenu(){
		//initBG();
		$('.commonPage .navigation-container-2 ul.main-menu-2 li').each(function(){
			if($(this).hasClass('has-sub')){
				//console.log(11);
				$(this).find('a.parent').attr('href','javascript:void(0);');
			}	
			var menu = $(this).find('a').attr('linkto');
			var current = $('input[name="cate_code_active"]').val();
			//console.log(menu , current);
			if(menu == current){
				$(this).parents('li').addClass('active');
				$(this).parents('li').find('ul.sub').show();
				$(this).addClass('active');
				//$(this).find('a').addClass('current');
			}
		});
		$(window).load(function(){
			setPage();
		});
		
		
		$(".commonPage .box-left ul.main-menu-2 li a[href='javascript:void(0);']").click(function() { 
			//alert(1);
			$(".commonPage .box-left ul.main-menu-2 li").removeClass('active current');
			$(this).parent().addClass('active');
			$(".commonPage .box-left ul.main-menu-2 li ul.sub").hide().removeClass('open');
		    $(this).parent().find('ul.sub').addClass('open');
		    if($(this).parent().find('ul.sub').hasClass('open')){
		    	$(this).parent().find('ul.sub').show().removeClass('open');	
		    }else{
		    	$(this).parent().find('ul.sub').hide().addClass('open');
		    }
		});
	}
	
	function extractPageName(hrefString)
	{
		var arr = hrefString.split('/');
		return  (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase(); 
		             
	}
	
	function setActiveMenu(arr, crtPage)
	{
		//console.log(arr);
		for (var i=0; i<arr.length; i++)
		{
			if(extractPageName(arr[i].href) == crtPage)
			{
				if (arr[i].parentNode.tagName != "DIV")
				{
					arr[i].className = "current";
					arr[i].parentNode.className = "current";
					$(arr[i].parentNode).parents('li.has-sub').addClass('active');
					$(arr[i].parentNode).parents('li.has-sub').find('ul.sub').show();
				}
			}
		}
	}
	
	function setPage()
	{
		hrefString = document.location.href ? document.location.href : document.location;
		setActiveMenu($(".main-menu-2").find("a"), extractPageName(hrefString));
		//setActiveMenu($(".main-menu-2").find("a"), extractPageName(hrefString));
	}
	
	function createSlide(){
		var bdrap = true;
		$("#uneven_slider").touchme({
			preventDefaultEvents: false,
			isDetectHorizontalMovement:true,
			isDetectVecticalMovement:true,
			isDetectDiagonalMovement:true,
			wipeLeft: function(target) {
				$('.uneven').slickNext();
			},
			wipeRight: function(target) {
				$('.uneven').slickPrev();
			}
		}); 
		
		bdrap = false;
		$('.uneven').slick({
		  infinite: true,
		   speed: 1000,
		    autoplay: true,
			autoplaySpeed: 3000,
		  slidesToShow: 5,
		  slidesToScroll: 5,
		  swipe:bdrap,
		  draggable:true,
		  responsive: [
		    {
		      breakpoint: 1150,
		      settings: {
		        slidesToShow: 4,
		        slidesToScroll:4
		      }
		    },
		    {
		      breakpoint: 768,
		      settings: {
		        slidesToShow: 3,
		        slidesToScroll:3
		      }
		    },
		   
		  ]
		});
	}
	function createRating(){
		/*Rating 1*/
		$('#rating-1').rating({
              min: 0,
              max: 5,
              step: 1,
              size: 'lg'
        });
       
        $('#rating-1').on('rating.change', function() {
            console.log($('#rating-1').val());
        });
        
        /*Rating 2*/
        $('#rating-2').rating({
              min: 0,
              max: 5,
              step: 1,
              size: 'lg'
        });
       
        $('#rating-2').on('rating.change', function() {
            console.log($('#rating-2').val());
        });
        
        /*Rating 3*/
        $('#rating-3').rating({
              min: 0,
              max: 5,
              step: 1,
              size: 'lg'
        });
       
        $('#rating-3').on('rating.change', function() {
            console.log($('#rating-3').val());
        });
        
        /*Rating 4*/
        $('#rating-4').rating({
              min: 0,
              max: 5,
              step: 1,
              size: 'lg'
        });
       
        $('#rating-4').on('rating.change', function() {
            console.log($('#rating-4').val());
        });
        
        /*Rating 2*/
        $('#rating-5').rating({
              min: 0,
              max: 5,
              step: 1,
              size: 'lg'
        });
       
        $('#rating-5').on('rating.change', function() {
            console.log($('#rating-5').val());
        });
	}
	function setBG(){
		$('.menu ul li').each(function(){
			var color = $(this).attr('color');
			$(this).css('background-color','#'+color);
		});
		$('ul.li-page5 li').each(function(){
			var color = $(this).attr('bg');
			$(this).css('background','#'+color);
		});
	}
	
	
	function hoverMenu(){
		var arrow = webroot + 'images/arrow.png';
		$('.commonPage .box-left ul.main-menu li').hover(function(){
			var color = $(this).attr('color');
			
			if($(this).hasClass('has-sub')){
				$(this).css({'background':'url('+arrow+') no-repeat scroll 145px center #' + color});
			}else{
				$(this).css({'background':'#' + color});
			}
		},function(){
			$(this).removeAttr('style');
		});
		
		
	}

	/*
=======
	function toggleMenu(){
		$(".commonPage .navigation-container-2 ul.main-menu-2 li.has-sub ul.sub").hide();
		  $(".commonPage .navigation-container-2 ul.main-menu-2 li.has-sub ul.sub").delegate("li.has-sub", "click", function() { 
		      $(this).next().toggle("fast").siblings("ul.sub").hide("fast");
		  });
	}
	
>>>>>>> 185c8495d8d70a3745f94801dcdbd03b51109c37
	function continue_step2(){
		$('#continue-step2').click(function(){
			var step = $(this).attr('step');
			$('.type-info .steps .step').removeClass('active');
			$("#"+step).addClass('active');
			$('.type-info .step-form .step-left .step').css({'display':'none'});
			$('.type-info .step-form .step-left .step.'+step).css({'display':'block'});
			return false;
		});
	}
    */    
	return {
		init:init
	}
})();		

$(document).ready( function() {
	SiteMain.init();
});

